package logic

import (
	"context"
	"house_srv/home"
	"house_srv/internal/svc"
	"house_srv/models"

	"github.com/zeromicro/go-zero/core/logx"
)

type HomeListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewHomeListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *HomeListLogic {
	return &HomeListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *HomeListLogic) HomeList(in *home.HomeListRequest) (*home.HomeListResponse, error) {
	var h models.Home
	homelist, err := h.Findlist()
	if err != nil {
		logx.Error("房源列表展示失败", err)
		return nil, err
	}
	var homelists []*home.HomeList
	for _, h2 := range homelist {
		list := home.HomeList{
			Title:   h2.Title,
			Address: h2.Address,
			Num:     int64(h2.Num),
			Price:   float32(h2.Price),
		}
		homelists = append(homelists, &list)
	}

	return &home.HomeListResponse{
		List: homelists,
	}, nil
}
